<?php

class Default_Model_EquipmentField extends Zend_Db_Table_Abstract
{
    protected $_name = 'equipment_field';
    
    public function deleteFieldByEquipmentId ($equipmentId)
    {
    	$this->delete( array('equipmentId = ?' =>(int) $equipmentId));
    }
    public function addEquipmentField ($equipmentId, $fieldId, $value)
    {
        $data = array (
            'equipmentId' =>$equipmentId ,'fieldId' => $fieldId, 'value' => $value
        );
        try{
        	return $this->insert( $data );
        }catch(Zend_Exception $exp)
        {
        	//echo 'Error!: ' . $exp->getMessage();
        	return false;
        }
    }
    public function getEquipmentData($equipmentId){
        $query = $this->select()
                    ->from($this->_name)
                    ->where('equipmentId = ?',$equipmentId)
                    ->order('fieldId ASC');
        return $this->fetchAll($query);
    }
    public function deleteEquipmentId ($equipmentId)
    {

        $this->delete( array('equipmentId = ?' =>(int) $equipmentId  ));
    }
    public function deleteFieldId ($fieldId)
    {

        $this->delete( array('fieldId = ?' =>(int) $fieldId  ));
    }
    public function updateEquipmentField ($equipmentId, $fieldId, $value)
    {

        $data = array (
            'value' => $value
        );
        $this->update( $data,  array('equipmentId = ?' =>(int) $equipmentId ,'fieldId = ?' =>(int) $fieldId  ) );
    }
    // chua su dung
    
    public function deleteEquipmentField ($equipmentId, $fieldId)
    {

        $this->delete( array('equipmentId = ?' =>(int) $equipmentId ,'fieldId = ?' =>(int) $fieldId  ));
    }
    public function findForSelect ()
    {

        $select = $this->select();
        return $this->fetchAll( $select );
    }
    
}

























